package com.qf.vip.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.vip.entity.Users;
import com.qf.vip.mapper.UsersMapper;
import com.qf.vip.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_vip
 * @Package com.qf.vip.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 15:58
 */

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    @Transactional
    public void update(Users users) {
        int i = usersMapper.updateByPrimaryKeySelective(users);
        if (i != 1){
            throw new RuntimeException("修改失败");
        }
    }

    @Override
    public Users findByNameAndPwd(String name, String pwd) {
       return usersMapper.selectByNameAndPwd(name,pwd);
    }

    @Override
    public List<Users> findAll() {
        return usersMapper.selectByExample(null);
    }

    @Override
    public PageInfo<Users> findByTypeIdAndPage(Integer pageNum, Integer pageSize,Integer typeId) {

        PageHelper.startPage(pageNum, pageSize);
        List<Users> list = usersMapper.selectByTypeId(typeId);
        PageInfo<Users> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
